//
//  ADSuyiCustomAdapterTestIntertitalAd.m
//  ADSuyiCustomPlatform
//
//  Created by Erik on 2021/9/6.
//

#import "ADSuyiCustomAdapterTestIntertitalAd.h"
#import <BUAdSDK/BUNativeExpressInterstitialAd.h>
@interface ADSuyiCustomAdapterTestIntertitalAd ()<BUNativeExpresInterstitialAdDelegate>
{
    BUNativeExpressInterstitialAd *_interstitialAd;
    ADSuyiCustomAdapterRequestContext *_context;
}
@end

@implementation ADSuyiCustomAdapterTestIntertitalAd

+ (void)load {
    [self registPlatformAdLoaderClass:self forSdkName:@"toutiao" renderType:(ADSuyiAdapterRenderTypeExpress)];
}

#pragma mark - request

- (void)requestAdWithContext:(ADSuyiCustomAdapterRequestContext *)context {
    _context = context;
    if(!_interstitialAd) {
        _interstitialAd = [[BUNativeExpressInterstitialAd alloc] initWithSlotID:context.posId adSize:CGSizeMake(300, 300)];
        _interstitialAd.delegate = self;
    }
    [self trackInterstitialAdRequest];
    [_interstitialAd loadAdData];
}

- (void)showInterstitalAdFromViewController:(UIViewController *)viewController {
    if (!viewController) {
        viewController = _context.viewController;
    }
    [_interstitialAd showAdFromRootViewController:viewController];
}

#pragma mark - intertital delegate

/**
 This method is called when interstitial ad material loaded successfully.
 */
- (void)nativeExpresInterstitialAdDidLoad:(BUNativeExpressInterstitialAd *)interstitialAd {
    [self trackInterstitialAdSuccessToLoad];
}

/**
 This method is called when interstitial ad material failed to load.
 @param error : the reason of error
 */
- (void)nativeExpresInterstitialAd:(BUNativeExpressInterstitialAd *)interstitialAd didFailWithError:(NSError * __nullable)error {
    [self trackInterstitialAdFailToLoadError:error];
}

/**
 This method is called when rendering a nativeExpressAdView successed.
 */
- (void)nativeExpresInterstitialAdRenderSuccess:(BUNativeExpressInterstitialAd *)interstitialAd {
    
    
}

/**
 This method is called when a nativeExpressAdView failed to render.
 @param error : the reason of error
 */
- (void)nativeExpresInterstitialAdRenderFail:(BUNativeExpressInterstitialAd *)interstitialAd error:(NSError * __nullable)error {
    
}

/**
 This method is called when interstitial ad slot will be showing.
 */
- (void)nativeExpresInterstitialAdWillVisible:(BUNativeExpressInterstitialAd *)interstitialAd {
    [self trackInterstitialAdDidExposure];
}

/**
 This method is called when interstitial ad is clicked.
 */
- (void)nativeExpresInterstitialAdDidClick:(BUNativeExpressInterstitialAd *)interstitialAd {
    [self trackInterstitialAdDidClick];
}

/**
 This method is called when interstitial ad is about to close.
 */
- (void)nativeExpresInterstitialAdWillClose:(BUNativeExpressInterstitialAd *)interstitialAd {
    
}

/**
 This method is called when interstitial ad is closed.
 */
- (void)nativeExpresInterstitialAdDidClose:(BUNativeExpressInterstitialAd *)interstitialAd {
    [self trackInterstitialAdDidClose];
}

/**
 This method is called when another controller has been closed.
 @param interactionType : open appstore in app or open the webpage or view video ad details page.
 */
- (void)nativeExpresInterstitialAdDidCloseOtherController:(BUNativeExpressInterstitialAd *)interstitialAd interactionType:(BUInteractionType)interactionType {
    
}

@end
